import * as constant from './constant'
import { fromJS } from 'immutable'
import axios from 'axios'

const getArticleData = ( result ) => ({
    type: constant.GET_ARTICL_DATA,
    articleList: result.articleList
})
const addMoreData = ( list, nextPage ) => ({
    type: constant.GET_MORE_ARTICLE,
    list: fromJS(list),
    nextPage
})
export const getArticleList = () => {
    return (dispatch) => {
            axios.get('/api/home.json').then((res) => {
                const result = res.data.data;
                dispatch( getArticleData(result) );
            })     
   }   
}
export const getMoreList = (page) => {
    return (dispatch) => {
            axios.get('/api/homeList.json?page' + page).then((res) => {
                const result = res.data.data;
                dispatch( addMoreData(result, page + 1) );
            })   
   }   
}